package com.laikan.reader.bookfriend.activity;

import android.content.Intent;
import android.os.Handler;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;
import com.laikan.library.components.activitys.BasicActivity;
import com.laikan.reader.R;

/**
 * 提示注册领取活动礼包
 */
public class RegisterFestivalCouponActivity extends BasicActivity implements OnClickListener {

    private TextView tv_register;
    private TextView tv_cancel;
    private ImageView iv_close;

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_register:    // 领取
                Intent intent = new Intent(mContext, LoginActivity.class);
                startActivity(intent);
                exit();
                break;
            case R.id.tv_cancel:    // 取消
                exit();
                break;

            case R.id.iv_close:
                exit();
                break;
        }
    }

    private void exit() {
        new Handler() {
        }.postDelayed(new Runnable() {
            @Override
            public void run() {
                finish();
            }
        }, 500);
    }

    @Override
    protected void assignViews() {
        setContentView(R.layout.lk_register_festival_coupon);
        tv_register = (TextView)findViewById(R.id.tv_register);
        tv_cancel = (TextView)findViewById(R.id.tv_cancel);
        iv_close = (ImageView)findViewById(R.id.iv_close);
    }

    @Override
    protected void initData() {
        String name = getIntent().getStringExtra("name");
        if (TextUtils.isEmpty(name)) {
            tv_register.setText("领取");
        }else {
            tv_register.setText(name);
        }
    }

    @Override
    protected void setListener() {
        tv_register.setOnClickListener(this);
        tv_cancel.setOnClickListener(this);
        iv_close.setOnClickListener(this);
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {

        switch (keyCode) {
            case KeyEvent.KEYCODE_BACK:
                exit();
                return true;
        }
        return super.onKeyDown(keyCode, event);
    }

}
